home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 12.0 KB | 427 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWRect.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _XMPTYPES_
- #include <XMPTypes.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
- #include <ToolUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- //==============================================================================
- // •• RunTime Info
- //==============================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphx
- #endif
-
- //==============================================================================
- // •• struct FW_CRect
- //==============================================================================
-
- inline XMPCoordinate Min( XMPCoordinate a, XMPCoordinate b ) {return a<b ?a :b;}
- inline XMPCoordinate Max( XMPCoordinate a, XMPCoordinate b ) {return a>b ?a :b;}
-
- //------------------------------------------------------------------------------
- // • FW_CRect::FW_CRect
- //------------------------------------------------------------------------------
-
- FW_CRect::FW_CRect(const FW_CPoint &topLeft, const FW_CPoint &botRight)
- {
- left = topLeft.x; right = botRight.x;
- top = topLeft.y; bottom = botRight.y;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::FW_CRect
- //------------------------------------------------------------------------------
-
- FW_CRect::FW_CRect(const FW_CPoint &topLeft, XMPCoordinate width, XMPCoordinate height )
- {
- left = topLeft.x; right = left + width;
- top = topLeft.y; bottom= top + height;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect:: operator=
- //------------------------------------------------------------------------------
-
- FW_CRect& FW_CRect:: operator=(const XMPRect& xmpRect)
- {
- left = xmpRect.left; right = xmpRect.right;
- top = xmpRect.top; bottom= xmpRect.bottom;
-
- return *this;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::FW_CRect
- //------------------------------------------------------------------------------
-
- FW_CRect::FW_CRect(const FW_SPlatformRect &plfmRect)
- {
- #ifdef FW_BUILD_MAC
- left = ff(plfmRect.left); right = ff(plfmRect.right);
- top = ff(plfmRect.top); bottom= ff(plfmRect.bottom);
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect:: operator=
- //------------------------------------------------------------------------------
-
- FW_CRect& FW_CRect:: operator=(const FW_SPlatformRect &plfmRect)
- {
- #ifdef FW_BUILD_MAC
- left = ff(plfmRect.left); right = ff(plfmRect.right);
- top = ff(plfmRect.top); bottom= ff(plfmRect.bottom);
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
-
- return *this;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Set
- //------------------------------------------------------------------------------
-
- void FW_CRect::Set(XMPCoordinate l, XMPCoordinate t, XMPCoordinate r, XMPCoordinate b)
- {
- left = l; right = r;
- top = t; bottom= b;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Set
- //------------------------------------------------------------------------------
-
- void FW_CRect::Set(const FW_CPoint &topLeft, XMPCoordinate width, XMPCoordinate height)
- {
- left = topLeft.x; right = left+width;
- top = topLeft.y; bottom= top +height;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::SetInt
- //------------------------------------------------------------------------------
-
- void FW_CRect::SetInt(short l, short t, short r, short b)
- {
- left = ff(l); right = ff(r);
- top = ff(t); bottom= ff(b);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Offset
- //------------------------------------------------------------------------------
-
- void FW_CRect::Offset(XMPCoordinate x, XMPCoordinate y)
- {
- left += x; right += x;
- top += y; bottom+= y;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Offset
- //------------------------------------------------------------------------------
-
- void FW_CRect::Offset(const FW_CPoint &pt)
- {
- left += pt.x; right += pt.x;
- top += pt.y; bottom+= pt.y;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Place
- //------------------------------------------------------------------------------
-
- void FW_CRect::Place(XMPCoordinate x, XMPCoordinate y)
- {
- right += x - left;
- left = x;
- bottom += y - top;
- top = x;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Place
- //------------------------------------------------------------------------------
-
- void FW_CRect::Place(const FW_CPoint &pt)
- {
- right += pt.x - left;
- left = pt.x;
- bottom += pt.y - top;
- top = pt.y;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Inset
- //------------------------------------------------------------------------------
-
- void FW_CRect::Inset(XMPCoordinate x, XMPCoordinate y )
- {
- left += x;
- right -= x;
- top += y;
- bottom -= y;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Clear
- //------------------------------------------------------------------------------
-
- void FW_CRect::Clear( )
- {
- left = right = top = bottom = 0;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect:: operator&=
- //------------------------------------------------------------------------------
-
- void FW_CRect:: operator&=(const FW_CRect &r)
- {
- left = Max(left,r.left); right = Min(right, r.right);
- top = Max(top, r.top); bottom= Min(bottom,r.bottom);
- }
-
-
- //------------------------------------------------------------------------------
- // • FW_CRect:: operator|=
- //------------------------------------------------------------------------------
-
- void FW_CRect:: operator|= (const FW_CRect &r)
- {
- left = Min(left,r.left);
- right= Max(right,r.right);
- top = Min(top,r.top);
- bottom=Max(bottom,r.bottom);
- }
-
- //------------------------------------------------------------------------------
- // • operator|= FW_CPoint
- //------------------------------------------------------------------------------
-
- void FW_CRect:: operator|= (const FW_CPoint &pt)
- {
- left = Min(left,pt.x);
- right= Max(right,pt.x);
- top = Min(top,pt.y);
- bottom=Max(bottom,pt.y);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::AsPlatformRect
- //------------------------------------------------------------------------------
-
- void FW_CRect::AsPlatformRect(FW_SPlatformRect &plfmRect) const
- {
- #ifdef FW_BUILD_MAC
- SetRect(&plfmRect, FixedToInt(left), FixedToInt(top), FixedToInt(right), FixedToInt(bottom));
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::operator FW_SPlatformRect() const
- //------------------------------------------------------------------------------
-
- FW_CRect::operator FW_SPlatformRect() const
- {
- FW_SPlatformRect plfmRect;
-
- #ifdef FW_BUILD_MAC
- SetRect(&plfmRect, FixedToInt(left), FixedToInt(top), FixedToInt(right), FixedToInt(bottom));
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
-
- return plfmRect;
- }
-
- //------------------------------------------------------------------------------
- // FW_CRect::IsEmpty
- //------------------------------------------------------------------------------
-
- FW_Boolean FW_CRect::IsEmpty() const
- {
- return right<=left || bottom<=top;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Contains
- //------------------------------------------------------------------------------
-
- FW_Boolean FW_CRect::Contains(const FW_CPoint &pt) const
- {
- return left<=pt.x && pt.x<right
- && top <=pt.y && pt.y<bottom;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Contains
- //------------------------------------------------------------------------------
-
- FW_Boolean FW_CRect::Contains( const FW_CRect &r) const
- {
- return left<=r.left && r.right<=right
- && top <=r.top && r.bottom<=bottom;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::operator==
- //------------------------------------------------------------------------------
-
- FW_Boolean FW_CRect::operator==(const FW_CRect &r) const
- {
- return (left == r.left && top == r.top && right == r.right && bottom == r.bottom);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::IsIntersecting
- //------------------------------------------------------------------------------
-
- FW_Boolean FW_CRect::IsIntersecting(const FW_CRect &r) const
- {
- return Max(left,r.left) < Min(right,r.right)
- && Max(top,r.top) < Min(bottom,r.bottom);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Intersects
- //------------------------------------------------------------------------------
-
- FW_CRect FW_CRect::Intersects(const FW_CRect &r) const
- {
- FW_CRect result;
-
- result.left = Max(left,r.left);
- result.top = Max(top,r.top);
- result.right = Min(right,r.right);
- result.bottom = Min(bottom,r.bottom);
-
- if (result.IsEmpty())
- result.Set(0,0,0,0);
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::Sort
- //------------------------------------------------------------------------------
-
- void FW_CRect::Sort()
- {
- if (left > right)
- {
- XMPCoordinate temp = left;
- left = right;
- right = temp;
- }
- if (top > bottom)
- {
- XMPCoordinate temp = top;
- top = bottom;
- bottom = temp;
- }
- }
-
- //-------------------------------------------------------------------------
- // • FW_CRect::Map
- //-------------------------------------------------------------------------
-
- void FW_CRect::Map(const FW_CRect& srcRect, const FW_CRect& dstRect)
- {
- XMPCoordinate ratio = ::FixDiv(right - left, srcRect.right - srcRect.left);
-
- left += ::FixMul(dstRect.left - srcRect.left, ratio);
- right += ::FixMul(dstRect.right - srcRect.right, ratio);
-
- ratio = ::FixDiv(bottom - top, srcRect.bottom - srcRect.top);
-
- top += ::FixMul(dstRect.top - srcRect.top, ratio);
- bottom += ::FixMul(dstRect.bottom - srcRect.bottom, ratio);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::operator[]
- //------------------------------------------------------------------------------
-
- FW_CPoint& FW_CRect::operator[](FW_PointSelector sel)
- {
- if (sel == FW_kTopLeft)
- return *((FW_CPoint *) &left);
- else
- return *((FW_CPoint *) &right);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRect::operator[]
- //------------------------------------------------------------------------------
-
- const FW_CPoint& FW_CRect::operator[](FW_PointSelector sel) const
- {
- if (sel == FW_kTopLeft)
- return *((FW_CPoint *) &left);
- else
- return *((FW_CPoint *) &right);
- }
-
- //----------------------------------------------------------------------------------------
- // • FW_CRect::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CRect::Flatten(FW_CWritableStream& stream)
- {
- stream.Write((char*)this, sizeof(XMPRect));
- }
-
- //----------------------------------------------------------------------------------------
- // • FW_CRect::Unflatten
- //----------------------------------------------------------------------------------------
-
- void FW_CRect::Unflatten(FW_CReadableStream& stream)
- {
- stream.Read((char*)this, sizeof(XMPRect));
- }
-
-
-
-
-
-